package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.TrainPrepare;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 教师备课资料设置 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-08-16
 */
@Mapper
public interface TrainPrepareMapper extends BaseMapper<TrainPrepare> {



    @Select({"<script>",
            "SELECT" ,
                    "t1.* ," ,
                    "getSubjectsName(t1.subjects_id) AS subjects_name," ,
                    "getCourseTypeName(t1.class_type_id) AS class_type_name," ,
                    "t2.`name` as lesson_type_name," ,
                    "t3.name AS version_name" ,
                    "FROM" ,
                    "train_prepare as t1 INNER JOIN dict as t2 on t1.lesson_type = t2.num and type = 23",
                    "LEFT JOIN edu_version AS t3 ON t3.id = t1.version_id",
            "where 1=1",
            "AND t1.deleted = 0",
            "<when test='yearPart!=null and yearPart!=&apos;&apos; '>",
            "AND t1.year_part = ${yearPart} ",
            "</when>",
            "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
            "AND t1.quarter_num = ${quarterNum} ",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "AND t1.year_class_id = ${yearClassId} ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
            "AND t1.subjects_id = ${subjectsId} ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "AND t1.class_type_id = ${classTypeId} ",
            "</when>",

            "<when test='lessonType!=null and lessonType!=&apos;&apos; '>",
            "AND t1.lesson_type = ${lessonType} ",
            "</when>",

            "<when test='versionId!=null and versionId!=&apos;&apos; '>",
            "AND t1.version_id = ${versionId} ",
            "</when>",
            "ORDER BY t1.created_at DESC",
            "</script>"
    })
    public IPage<TrainPrepare> findAll(
            IPage<?> page,
            @Param("yearPart") String yearPart,
            @Param("quarterNum") String quarterNum,
            @Param("yearClassId") String yearClassId,
            @Param("subjectsId") String subjectsId,
            @Param("classTypeId") String classTypeId,
            @Param("lessonType") String lessonType,
            @Param("versionId") String versionId
    );

}
